package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 攻略文章
 */
@Getter@Setter
public class StrategyDetail extends BaseDomain {
    /**
     * 0 草稿
     * 1 发布
     * -1 禁用
     */
    public static final int STATE_COMMON=0;
    public static final int STATE_RELEASE=1;
    public static final int STATE_DISABLE=-1;
    //标题
    private String title;
    //创建时间
    private Date createTime;
    //发布时间
    private Date releaseTime;
    //排序 序号
    private Integer sequence;
    //所属攻略目录
    private StrategyCatalog catalog;
    //封面
    private String coverUrl;
    //状态
    private Integer state;


    //攻略内容
    private StrategyContent strategyContent;



    //页面状态汉字回显
    public String getStateName() {
        String msg="草稿";
        if (state==STATE_RELEASE) {
            msg="热门";
        }else if (state==STATE_DISABLE){
            msg="禁用";
        }
        return msg;
    }

    /**
     * 增加一个属性 json对象
     * @return
     */
    public String getJson() {
        Map<String,Object> map= new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        map.put("sequence",sequence);
        map.put("state",state);
        if (catalog != null) {
            map.put("catalogId",catalog.getId());
            map.put("catalogName",catalog.getName());
            if(catalog.getStrategy()!=null){
                //只需要大攻略的id
                map.put("strategyId",catalog.getStrategy().id);
            }
        }
        return JSONUtil.toJSONString(map);
    }

}